<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<title>_订单打印</title>


<script type="text/javascript">
 
  $(function() {
		$("#queryForm").validate(); 
		$("#_fromDate").datepicker({ format:'yyyy-mm-dd'});
		$("#_toDate").datepicker({ format:'yyyy-mm-dd'});
		var now = new Date();
		var tomorrow = new Date();
		tomorrow.setDate(now.getDate()+1);
		if(!$("#_fromDate").val()){
			$("#_fromDate").val(now.Format("yyyy-MM-dd"));
		}
		if($("#_toDate").val() == ''){
			$("#_toDate").val(tomorrow.Format("yyyy-MM-dd"));
		}
		var flag='${flag}';
		if(flag=='order'){
		   $("[name='order']").show();
		   $("[name='task']").hide();
		}else if(flag=='task'){
		   $("[name='order']").hide();
		   $("[name='task']").show();
		} 
		//绑定checkbox
		 bindCheckBox("myCheckedAll","myChecked");
  });
  
  //打印单件
  function print(taskCode){
     alert(taskCode);
  }
  
  //重新打印
  function reprint(taskCode){
     alert(taskCode);
  }
  
    var packformStyleId = 0;
	var number = 30;//每次打印的数量
	var workIds = "0";
	var nextOrdeno = "begin";//打印最后一个订单号
	var packStyleName = "OSA-A5";//随箱单名称
	var packStyleType = "A5";//随箱单类型
	var printName = "";//打印机名称
	var expressRex="";//运单号正则表达式
    var workId=0;
    var taskCode="";
	var packFormStylePage = "";
	var expressId=0;
	var expressType="normal";
	
	var succedOrdenos="";
	var pageExpressOrdenos="";
	var firstExpress="";//起始快递单号
	var endExpress="";//终止快递单号

	function ajaxPackFormCount( callback ) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPackFormCount',
			data : 'workIds=' + workIds + '&number=' + number,
			dataType : 'json',
			success : function(data) {
				if (data.status == 1) {
					packFormStylePage = data.content;
				}
				callback && callback();
			},

			error : function() {

			}
		});
	}

	function ajaxExpressCount(workId,firstExpress,expressID,printName) {
		 showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxExpressCount',
			data : {
				workIds:workId,
				number:number,
				firstExpress:firstExpress,
				expressID:expressID
				
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == 1) {
					 
					pageExpressOrdenos = data.content;
					 var pageLists=pageExpressOrdenos.split(",");
					    for(var i=0;i<pageLists.length;i++){
					    	if(""==pageLists[i]){
					    		continue;
					    	}
					    	$.ajaxQueue.offer({
								type : 'post',
								url : '${ctx}/print/ajaxPrintQueueExpress',
								data :{
									queues:pageLists[i],
									expressId:expressId
								} ,
								dataType : 'json',
								success : function(data) {

								},
								beforeSend : function(jqXHR, settings) {

								},
								success : function(data, textStatus, jqXHR) {
									if (data.status == "1") {
										$.each(data.content,function(i){
											     var str=data.content[i].content;
												 str=str.replace(/\r\n|\n|\r/g,"");
											     printExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
											});
										if(data.index=="finish"){
											 showExpressWork(workId);
											closeBg();
											
										}
									} else {
										alert(data.content);
									}
									
								}
							});
					    }
					
				}else{
					alert(data.content);
					closeBg();
				}
			},

			error : function() {

			}
		});
	}
	
	function printAjaxGuarantee(){
		printName = $("#guaranteeStylePrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintGuarantee',
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
						$.each(data.workOrders,function(i,v){
							printGuarantee(v,printName);
						});
						
					updateGuanteeStatus(taskCode);
					} else {
						closeBg();
					}
				 }
		});
	}
	
	function updateGuanteeStatus(taskCode){
		$.ajax({
			type : 'post',
			url : '${ctx}/print/updateGuarantee',
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data){
			if (data.status == "1") {
					 closeBg();
				} else {
					alert(data.content);
				}
			},
			error : function() {
					closeBg();
			}
		});
	}
	
	function ajaxEbillExpressCount(taskCode,expressID,printName) {
		showBg();
		
		//add 增加两个计数变量  bug414 byzhangweize
		var firstCount =0;
		var secondeCount =0;
		
		$.ajax({
			type : 'post',
			url : '${ctx}/print/spliteEbillOrder',
			data : {
				taskCode:taskCode,
				size:number
			},
			dataType : 'json',
			timeout : 240000,//add 增加两个计数变量  bug414 byzhangweize
			success : function(data) {
				if (data.status == 1) {
					pageExpressOrdenos = data.content;
					 var pageLists=pageExpressOrdenos.split(";");
					    for(var i=0;i<pageLists.length;i++){
					    	if(""==pageLists[i]){
					    		continue;
					    	}
					    	if(pageLists[i]=="finish"){
					    		showExpressWork(workId);
					    		continue;
					    	}
					    	//add 增加计数变量加1  bug414 byzhangweize
					    	firstCount = firstCount +1 ;
					    	$.ajaxQueue.offer({
								type : 'post',
								url : '${ctx}/print/ajaxPrintEBillExpress',
								data :{
									ordenos:pageLists[i],
									expressId:expressID,
									taskCode:taskCode
								},
								dataType : 'json',
								timeout : 240000,//add 增加两个计数变量  bug414 byzhangweize
								success : function(data) {
									 if (data.status == "1") {
										 if(data.openCaiNiao == "1"){
										 	//初始化菜鸟控件
											//initCNPrint();
										 }
										$.each(data.content, function(i) {
											    var str=data.content[i].content;
											    str=str.replace(/\r\n|\n|\r/g,"");
											    if(data.openCaiNiao == "1"){
											    	printMailExpressByCaiNiao(printName,data.width,data.height,data.content[i]);
											    }else if("YUNDA"==data.expressStyle.logisticsCompany.companyCode){
											    	printYunDa(data.content[i].content,printName);
											    }else{
											    	if("YZM1" == data.content[i].customerCode){
												    	printMailExpressDg(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].expressNo,data.expressStyle,data.content[i].ordeno,data.content[i].customerCode);
												    }else{
												    	printMailExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].expressNo,data.expressStyle,data.content[i].ordeno);
												    }
											    }
										});
									    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
									} else if (data.status == "-3") {
										alert("请输入正确的运单号！");
									} else if (data.status == "0") {
										alert(data.content);
									}
								    //add 增加计数变量加1，并进行两个变量的判断  bug414 byzhangweize
									 secondeCount = secondeCount +1 ;
									if (firstCount == secondeCount){
										closeBg();
									}
									
								},
								error : function() {
									closeBg();
								}
							});
					    }
					   
				}else{
					alert(data.content);
					closeBg();
				}
			},

			error : function() {
					closeBg();
			}
		});
	}

////////////////准备删除////////////////////
function printFivePackStyleLove(taskName, printerName, printContent,ordeno, rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		LODOP.ADD_PRINT_BARCODE(20, 50, 350, 40, "128B", ordeno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printFivePackStyleRy(taskName, printerName, printContent, ordeno,rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(20, 50, 350, 40, "128B", ordeno);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printFivePackStyle(taskName, printerName, printContent, ordeno,expressNo,rankno,customerCode,printerLoGo) {
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5") ;
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(60, 0, "100%", "100%", strCenterStyle+ printContent);
		//LODOP.ADD_PRINT_BARCODE(60, 360, 150, 40, "128B", ordeno);
		eval(printerLoGo);//打印LoGo
		LODOP.ADD_PRINT_BARCODE(50, 560, 200, 50, "128B", ordeno);
	    //if(customerCode=="SUN"){
		//	LODOP.ADD_PRINT_BARCODE(480, 50, 0, 0, "128B", rankno);
		//}else{
		//	LODOP.ADD_PRINT_BARCODE(20, 10, 0, 0, "128B", rankno);
		//}
		////LODOP.ADD_PRINT_BARCODE(650, 280, 200, 20, "128B", expressNo);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
		
	}

	function printFourPackStyle(taskName, printerName, printContent, ordeno,expressNo, rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		LODOP.ADD_PRINT_BARCODE(10, 50, 350, 50, "128B", ordeno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printStyle(packStyleName,taskName, printerName, printContent, ordeno, expressNo,rankno,customerCode,printerLoGo) {
		
			printFivePackStyle(taskName, printerName, printContent, ordeno,expressNo,rankno,customerCode,printerLoGo);
		
	}
	
	function printFivePackStyleHS1(taskName, printerName, printContent, ordeno,rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 200, 20, rankno);

		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(30, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(10, 50, 380, 40, "128B", ordeno);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}
	//////////////////////////


	function myCheckedAllTWS() {
		var tempChecked = "";
		$("input[type='checkbox'][name='myChecked']:checked").each(function() {
			if (tempChecked == "") {
				tempChecked = $(this).val();
			} else {
				tempChecked = tempChecked + ":" + $(this).val();
			}
		});
		return tempChecked;
	}

	function changeCode() {
		var customerCode = $("#customers").val();
		window.location.href = "${ctx}/print/pageWorkBatchPrint/${lineType}/"+ customerCode;
	}

	

	function myCheckedAll() {
		var check = $("input[name='myChecked']");
	        check.each(function(n) {
	        if (check.eq(n).attr("disabled") != "disabled") {
	             check.eq(n).attr("checked",$("#myCheckedAll").is(":checked"));
	         }
	       });
		
	}

	function myChecked(item) {
		if ($(item).is(":checked")) {
		} else {
			$("#myCheckedAll").attr("checked", false);
		}
	}

	function printPackForm(item) {
		
		var customerCode = $("#_customerCode").val();
		if(customerCode == "" || customerCode == null){
			alert("请选择商家");
			return false;
		}
		
		workIds = myCheckedAllTWS();
		if (workIds == "") {
			$("#message").html("请选择流水号");
			$("#message").show();
			$(item).attr("href", "ss");
			workIds="0";
			hideMessage();
			return false;
		} else {
			showBg();
			$.ajax({
				type : 'post',
				url : '${ctx}/print/checkCustomerPackFormStatus',
				data : 'customerCode=' + customerCode,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						
 					  /* $(item).attr("href", "#printAllPackFormStyle");   */
					  
					    	ajaxPackFormCount( function(){
					    		closeBg();
					    	 $("#printAllPackFormStyle").modal('show');
					    	packFormPrinter("packFormStylePrint");
					    });
					} else {
						 $("#printAllPackFormStyle").modal('hide');
						 closeBg();
						alert(data.content);
					}
				},
				error : function() {
					 $("#printAllPackFormStyle").modal('hide');
					 closeBg();
					alert("该商家校验是否打印随箱单失败!");
				}
			});
			
		}
	}
	
	
	
	function printInitExpress(item){
	   workId=item;
        doGetPrinters();
	}
	
	function printInitGuarantee(item){
		taskCode=item;
		packFormPrinter("guaranteeStylePrint");
	}

	function printPackFormStyle() {
		showBg();
		workNoAjaxPrinter();
	}
	
	function initFirstExpress(code){
		$("#firstExpressNumber").val("");
		taskCode = code;
	}
	
	function pageAjaxPrintExpress(){
		var firstExpress = $("#firstExpressNumber").val();//运单号
		var esiValue = $("#expressStylesId").val();
		if(!esiValue){
			alert("请选择快递单");
			return;
		}
	    printName = $("#expressPrint").val();
	      if("normal"==expressType){
	        if(!verify(firstExpress)){
	           alert("请输入正确的订单号！");
	           return;
	         }  
	        ajaxExpressCount(workId,firstExpress,expressId,printName);
	      }else if("mail"==expressType){
	    	ajaxEbillExpressCount(taskCode,expressId,printName);
	      }else{
	    	ajaxExpressCount(workId,firstExpress,expressId,printName);
	      }
	      
	}
	
	
	
	function printWorkExpress(){
	      var firstExpress = $("#firstExpressNumber").val();//运单号
	      if("normal"==expressType){
	        if(!verify(firstExpress)){
	           alert("请输入正确的订单号！");
	           return;
	         }  
	      }
	      
	      printName = $("#expressPrint").val();
	      showBg();
	$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintPackExpress',
			data : 'workId=' + workId+'&firstExpress='+firstExpress+'&expressId='+expressId+'&printName='+printName,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					$.each(data.content,function(i){
					   var str=data.content[i].content;
						    str=str.replace(/\r\n|\n|\r/g,"");
							printExpress(data.content[i].taskName,data.content[i].printerName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
					
					});
				   ajaxSuccedOrdenos();
                   showExpressWork(workId);
				} else {
					alert(data.content);
				}
				closeBg();
				$("#firstExpressNumber").val("");
			},

			error : function() {

			}
		});
	}
	
	 function ajaxSuccedOrdenos() {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxSuccedOrdenos',
				data : 'ordenos=' + succedOrdenos,
				dataType : 'json',
				success : function(data) {
					ajaxSuccedOrdenos="";
				},
				error : function() {
					alert("服务器异常2");
				}
			});
		}
	 
	 //修改订单的快递单打印状态
	 function ajaxPrintExpressOrdeno(ordeno,expressNo,companyCode) {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxPrintExpressOrdeno',
				data : {
					ordeno:ordeno,
					expressNo:expressNo,
					companyCode:companyCode
				},
				dataType : 'json',
				success : function(data) {
					if(data.status=="1"){
						ajaxSuccedOrdenos+=ordeno;
					}
				},
				error : function() {
					alert("服务器异常3");
				}
			});
		}
	
	function showExpressWork(work){
		var lists=work.split(":");
		for(var i=0;i<lists.length;i++){
			 $("#express_"+lists[i]).attr("disabled","disabled");
			 if($("#check"+lists[i]).attr("disabled") == "disabled"){
				 $("#pendPackForm_"+lists[i]).remove();
			 }else{
				 $("#expressStyle"+lists[i]).html("<font color='red'>已打印快递单</font>");
			 }
		}
	   
	   
	}
	//打印快递单
	function printExpress(taskName,printerName,content,width,height,rankno,expressNo,ordeno,companyCode) {
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(1,width,height,""); 
		//LODOP.ADD_PRINT_TEXT(10,10,200,60,rankno);
		//LODOP.ADD_PRINT_BARCODE(10, 200, 180, 40, "128B", expressNo);//打印出快递运单条码，测试后删除。
		eval(content);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			var item=LODOP.PRINT(); 
			if(item){
				ajaxPrintExpressOrdeno(ordeno,expressNo,companyCode);
			}
		}
	}
	
function printGuarantee(workOrder,printName){
		LODOP.PRINT_INIT(workOrder.order.ordeno);
		LODOP.SET_PRINT_PAGESIZE(1,2400,1399,""); 
		var height=0;
		LODOP.ADD_PRINT_TEXT(90,'120mm',140,40,workOrder.taskCode+"_"+workOrder.rankno);
		LODOP.ADD_PRINT_TEXT(120,'120mm',140,40,"商业");
		LODOP.ADD_PRINT_TEXT(120,'50mm',140,40,new Date().Format("yyyy-MM-dd hh:mm:ss"));
		var count = 0;
		var order = workOrder.order.orderItems;
		for(var i =0;i<order.length;i++){
			height = height+30;
			LODOP.ADD_PRINT_TEXT(200+height,'50mm',140,40,order[i].nam);
			LODOP.ADD_PRINT_TEXT(200+height,'120mm',140,80,order[i].des);
			LODOP.ADD_PRINT_TEXT(200+height,'140mm',140,40,order[i].qty);
			LODOP.ADD_PRINT_TEXT(200+height,'160mm',140,80,order[i].pri);
			LODOP.ADD_PRINT_TEXT(200+height,'180mm',140,40,(order[i].pri)*(order[i].qty));
			count+=(order[i].pri)*(order[i].qty);
		}
		LODOP.ADD_PRINT_TEXT(390,'150mm',40,40,count);
		LODOP.ADD_PRINT_TEXT(440,'50mm',40,40,"梁欣");
		LODOP.ADD_PRINT_TEXT(440,'100mm',40,40,"梁欣");
		LODOP.ADD_PRINT_TEXT(440,'120mm',250,100,"佛山市顺德区盈丰行网络科技有限公司");
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}
	
	
	function workNoAjaxPrinter() {
		packformStyleId = $("#packformStylesId").val();//随箱单样式
		printName = $("#packFormStylePrint").val();
		var count = packFormStylePage.split(":");
		
		function task(){
			 var index = 0 , l = count.length;
			 var process = function(){
					$.ajax({
						type : 'post',
						url : '${ctx}/print/ajaxPrintPackForm',
						data :{
							workIds:workIds,
							number:number,
							nextOrdeno:count[index],
							packformStyleId:packformStyleId,
							printName:printName
						} ,
						dataType : 'json',

						beforeSend : function(jqXHR, settings) {

						},
						success : function(data, textStatus, jqXHR) {
							
							if (data.status == "1") {
								$.each(data.content, function(i) {
								   if(data.content[i].ordeno=="0"){
									 //该功能是原派友系统的功能，目前仓库的作业人员用不到,浪费纸张 libin
								     //printWorkBatch(data.content[i].taskName,printName, data.content[i].content,data.content[i].taskName);
								     //修改随箱单状态
								     
								      /***bug554 beigin remove by zhangweize 2016-10-31 *************/
								     //ajaxWorkTaskPrintStatus(data.content[i].taskName);
								      /***bug554 end remove by zhangweize *************/
								   }else{
								     printStyle(packStyleName,data.content[i].taskName ,printName, data.content[i].content,data.content[i].ordeno,data.content[i].expressNo,
								    		 data.content[i].taskName,data.content[i].customerCode,data.content[i].printerLoGo);
								   }
									
								});
								
								
		                      if(data.index=="finish"){
		                          /***bug554 beigin remove by zhangweize  2016-10-31  *************/
		                    	//ajaxWorkTaskPackFormStatus(workIds);
		                    	  /***bug554 end remove by zhangweize  2016-10-31*************/
		                    	  
	                    	    var lists=workIds.split(":");
	     					    for(var i=0;i<lists.length;i++){
		     					     $("#check"+lists[i]).attr("disabled",true);
		     					     $("#check"+lists[i]).attr("checked",false);
		     					     var value=$("#expressStyle"+lists[i]).html();
		     						 if("<font color=\"red\">已打印</font>"==value){
		     							  $("#pendPackForm_"+lists[i]).remove();
		     						  }
	     					    }
		                        closeBg();
		                      }
							} else {
								closeBg();
								alert(data.content);
							}
							
							if( index++ < l ){
								if(  count[index]  )
									process();
							}
						},
						error : function() {
							alert("打印随箱单服务器异常");
							closeBg();
						}
					});
				}
			 
			 showBg();
			 
			 if( l>0 && count[index] )  process();
		 }
		
		 task();
		return;
	}
	
	function ajaxWorkTaskPrintStatus(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxWorkTaskPrintStatus',
			data : 'taskCode=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					   var id=data.content.id;
					
					   $("#check"+id).attr("disabled",true);
					   $("#check"+id).attr("checked",false);
					   var value=$("#expressStyle"+id).html();
						  if("<font color=\"red\">已打印</font>"==value){
							  $("#pendPackForm_"+id).remove();
							  
						  }
					 
				} else {
					alert(data.content);
				}
			},
			error : function() {
				alert("服务器异常4");
			}
		});
	}
	
	
   function ajaxWorkTaskPackFormStatus(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxWorkTaskPackFormStatus',
			data : 'workIds=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					   var lists=workIds.split(":");
					
					  for(var i=0;i<lists.length;i++){
					     $("#check"+lists[i]).attr("disabled",true);
					     $("#check"+lists[i]).attr("checked",false);
					     var value=$("#expressStyle"+lists[i]).html();
						  if("<font color=\"red\">已打印</font>"==value){
							  $("#pendPackForm_"+lists[i]).remove();
							  
						  }
					  }
					 
				} else {
					alert(data.content);
				}
			},
			error : function() {
				alert("服务器异常5");
			}
		});
	}
	
	function printWorkBatch(taskName, printerName, printContent,rankno) {
		LODOP.PRINT_INIT(taskName);
        LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function hideMessage() {
		$(function() {
			setTimeout(function() {
				$("#message").hide();
			}, 3000);
		});
	}
	
	
	function verify(content) {
		var result =content.match(expressRex);
		if(result==null){
		  return false;
		}
		return true;
	}
	
	function getAjaxExpress() {
       var expressStylesId = $("#expressStylesId").val();
 
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/getAjaxExpress',
			data : 'expressStylesId=' + expressStylesId,
			dataType : 'json',
			success : function(data) {
				$("#startWaybillNODiv").attr("style","display:inline;");
				if (data.status == "1") {
					expressRex=data.content.logisticsCompany.regMailNo;
					expressId=data.content.id;
					expressType=data.content.type;
					if("mail"==expressType){
					   //$("#firstExpressNumber").attr("readOnly","readOnly");
					   $("#startWaybillNODiv").attr("style","display:none;");
					}else if("MJZT" == data.content.logisticsCompany.companyCode){
						$("#firstExpressNumber").val("XN"+Math.round(Math.random()*8999999999+1000000000));
					}
				}  else if (data.status == "0") {
					//alert("获取运单号正则表达式错误！");
				}
			},

			error : function() {

			}
		});
	}

	function getAjaxPackformStyle() {
		var packformStylesId = $("#packformStylesId").val();
		if (packformStylesId == "" || packformStylesId == null) {
			alert("还没有这个随箱单");
			return;
		}
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/packformStyle/getAjaxPackformStyle',
			data : 'packformStylesId=' + $("#packformStylesId").val(),
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {

					packStyleName = data.name;
					packStyleType = data.type;
					packformStyleContent = data.content;
				} else if (data.status == "0") {
					alert("获取随箱单信息错误！");
				}

			},
			error : function() {
				alert("服务器异常6");
			}
		});
	}
	

	 
	  function ajaxExpressStyle(companyCode,areaGroupCode,customerCode,type) {
		    type=(type=="cbill"? "normal":"mail");
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/expressPrinting/ajaxExpressStyle',
				data : 'companyCode=' + companyCode+'&areaGroupCode='+areaGroupCode+'&customerCode='+customerCode+'&type='+type,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						var temp="<option value=''></option>";
						$.each(data.content,function(i,obj){
						       temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
						});
						
						$("[name='expressStylesId']").html(temp);
						$("[name='expressStylesId']").trigger("chosen:updated");
						getAjaxExpress();
					}  
				},

				error : function() {

				}
			});
			
		}
	  
	  function ajaxVerifyExpress(item) {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxVerifyExpress',
				data : 'taskCode=' + item,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						var temp="";
						$.each(data.content,function(i,obj){
						    temp+="<tr><td>"+(i+1)+"</td><td>"+obj.expressNo+"</td></tr>";
						    if(i==0){
						    	firstExpress=obj.expressNo;
						    }else{
						    	endExpress=obj.expressNo;
						    }
						});
						$("#tableVerify").html(temp);
					}  
				},
				error:function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
			
		}
	  
	  function verifyExpressLists(item,type) {
			if("first"==type){
				if(item.value.trim()!=firstExpress){
					$("#firstSpan").html("<font color='red'>起始快递单号错误</font>");
				}else{
					$("#firstSpan").html("<font color='blue'>验证成功</font>");
					$("#endExpress").focus();
				}
			}else{
				if(item.value.trim()!=endExpress){
					$("#endSpan").html("<font color='red'>终止快递单号错误</font>");
				}else{
					$("#endSpan").html("<font color='blue'>验证成功</font>");
				}
			}
		}
	
	//------------------------------打印拣货单--------------------------------------------
	//修改拣货单样式  by 张卫泽
	function AjaxPagePrinter(){
		printName = $("#pickPickPrint").val();
		showBg();
		$.ajax({
			type : 'post',
			//url : '${ctx}/pickTask/ajaxPrintPickInfo', 
			url : '${ctx}/carPickTask/printFastPickTask', 
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data){
				if(data.status == "1"){
					//打印拣货单
					//printPickInfo(data.taskItemList,data.workOrderList,printName,data.printFlag);
					printPickInfo(data.workTaskItemList,data.printFlag,data.picker);
					closeBg();
					$("#print_"+data.workTaskItemList[0].taskCode).attr("disabled",true);
				}else{//bug 382 by zhangweize L882-L885
					alert(data.content);
					closeBg();
				}
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				closeBg();
			}
		});
	}
	function printPickInfo(taskItem,printFlag,picker){
			var taskCode = taskItem[0].taskCode;
			var adjustTop = 0;
		 	var adjustLeft = 0;
			var str = '';
			var num = 0;
			LODOP.PRINT_INIT(taskCode);
			//LODOP.ADD_PRINT_BARCODE((15+adjustTop)+"mm", (140+adjustLeft)+"mm", "45mm", "10mm", "128Auto", taskCode);
			LODOP.ADD_PRINT_BARCODE((10+adjustTop)+"mm", "65%", "45mm", "10mm", "128Auto", taskCode);
			str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
			str +="<thead>"
			str +="<tr><td colspan= '7' align = 'center'><h3>拣货单(任务编号："+taskCode+")&nbsp;&nbsp;第"+printFlag+"次打印</h3></td></tr>";
			str +="</thead>"
			str +="<tbody align = 'center'><tr><td colspan= '2'>仓库</td><td colspan= '2'>"+taskItem[0].warehouseCode+"</td></tr>";
			str += "<tr style='font-size:10pt'><td width='6%'>序号</td><td width='8%'>商家</td><td width='15%'>库位</td><td width='18%'>sku</td><td width='31%'>sku名称</td><td width='7%'>数量</td><td width='15%'>箱位指引</td></tr>";
			for(var i =0;i<taskItem.length;i++){
				str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].sku+"</td><td>"
				+taskItem[i].skuName+"</td><td>"+taskItem[i].num+"</td><td>"+taskItem[i].allocationDetail+"</td></tr>";
				num += taskItem[i].num;
			}
			str +="</tbody>";
			str +="<tfoot align = 'center'><tr><td colspan= '5'></td><td>"+num+"</td><td>拣货人:"+picker+"</td></tr></tfoot>";
			str +="</table>";
			LODOP.SET_PRINT_PAGESIZE(1, 0, 0, $("#paperSizes").val()) ;
			//bug382 by zhangweize L918 改成93%主要是防止分页的时候漏打。 
			//LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
			LODOP.ADD_PRINT_TABLE(10,0, "100%","93%",str);
			if (LODOP.SET_PRINTER_INDEXA($("#pickPickPrint").val())) {
				LODOP.PRINT(); 
			}
	   } 
	
	 /* function printPickInfo(taskItem,workOrderList,printName,printFlag){
		var taskCode = taskItem[0].taskCode;
		var adjustTop = 0;
	 	var adjustLeft = 0;
		var str = '';
		var num = 0;
		LODOP.PRINT_INIT(taskCode);
		LODOP.ADD_PRINT_BARCODE((10+adjustTop)+"mm", (80+adjustLeft)+"mm", "45mm", "10mm", "128Auto", taskCode);
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '7' align = 'center'><h3>拣货单(任务编号："+taskCode+")&nbsp;&nbsp;第"+printFlag+"次打印</h3></td></tr>";
		str +="<tbody align = 'center'><tr><td colspan= '2'>仓库</td><td colspan= '2'>"+taskItem[0].warehouseCode+"</td></tr>";
		//str += "<tr style='font-size:10pt'><td width='7%'>序号</td><td width='10%'>商家</td><td width='18%'>库位</td><td width='18%'>箱位</td><td width='20%'>sku</td><td width='20%'>sku名称</td><td width='7%'>数量</td></tr>";
		//for(var i =0;i<taskItem.length;i++){
		//	str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].boxCode+"</td><td>"+taskItem[i].sku+"</td><td>"+taskItem[i].skuName+"</td><td>"+taskItem[i].num+"</td></tr>";
		//	num += taskItem[i].num;
		//}
		str += "<tr style='font-size:10pt'><td width='6%'>序号</td><td width='8%'>商家</td><td width='15%'>库位</td><td width='15%'>箱位</td><td width='18%'>sku</td><td width='31%'>sku名称</td><td width='7%'>数量</td></tr>";
		for(var i =0;i<taskItem.length;i++){
			var tmpSkuName='';
			tmpSkuName=taskItem[i].skuName;
			if(tmpSkuName.length>20){
				tmpSkuName=tmpSkuName.substr(0,15)+"..."
			}
			str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].boxCode+"</td><td>"+taskItem[i].sku+"</td><td>"
			+tmpSkuName+"</td><td>"+taskItem[i].num+"</td></tr>";
			num += taskItem[i].num;
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '6'><h4>拣货单(任务编号："+taskCode+")</h4></td><td>"+num+"</td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A5") ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
		//美的打印拣货清单
		if("MID"==taskItem[0].customerCode){
			printPickDetailInfo(workOrderList,taskCode,printName);
		}
	}  */
	function printPickDetailInfo(workList,taskCode,printName){
		LODOP.PRINT_INIT(taskCode);
		var adjustTop = 0;
	 	var adjustLeft = 0;
		var str = '';
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '4' align = 'center'><h3>拣货清单(任务编号："+taskCode+")</h3></td></tr>";
		str += "<tbody><tr style='font-size:10pt'><td width='6%'>序号</td><td width='47%'>任务号</td><td width='22%'>商品名</td><td width='25%'>sku</td></tr>";
		for(var i =0;i<workList.length;i++){
			var itemSize = workList[i].voItem.length;
			str +="<tr style='font-size:10pt' ><td rowspan='"+itemSize+"'>"+(i+1)+"</td><td rowspan='"+itemSize+"'>"+workList[i].taskCode+"</td>";
			for(var j =0;j<itemSize;j++){
				str +="<td>"+workList[i].voItem[j].goodName+"</td><td>"+workList[i].voItem[j].skuAndqty.split(":")[0]+"("+workList[i].voItem[j].skuAndqty.split(":")[1]+")</td></tr>";
			}
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '4'><h4>拣货清单(任务编号："+taskCode+")</h4></td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A5") ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}
	
	
	   //init订单条码打印机
	  function initPrinter(batchCode) {
		   $("#nowBatchCode").val(batchCode) ;
		   packFormPrinter("printerBody");
	  }
	  function printBarCode(printName,orderno,b_t_r) {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			LODOP.PRINT_INIT(orderno);
			LODOP.SET_PRINT_PAGESIZE(1, 1000, 500, "");
			LODOP.ADD_PRINT_BARCODE(20, 25, 400, 65, "128B", orderno);
			LODOP.SET_PRINT_STYLE("FontName","SimHei");
		    LODOP.SET_PRINT_STYLE("FontSize",18);
			LODOP.ADD_PRINT_TEXT(90, 10, 500,10,b_t_r);//上左宽高
			if (LODOP.SET_PRINTER_INDEXA(printName)) {
				LODOP.PRINT();
			}
	  }
	  
	  //打印
	  function clickPrinter() {
		    var batchCode=$("#nowBatchCode").val();
		    var printName = $("#printerBody").val();
		    $.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxGetWorkOrderByBatchCode',
				data : {
					batchCode:batchCode
				},
				dataType : 'json',
				success : function(data) {
				    if(data.status == 1){
				       var workOrders = data.workOrders ;
				       for(var i=0;i<workOrders.length;i++){
				    	   var orderno = workOrders[i].order.ordeno ;
				    	   var b_t_r = workOrders[i].batchCode+"_"+workOrders[i].taskCode+"_"+workOrders[i].rankno ;
				    	   printBarCode(printName, orderno,b_t_r);
				       }
				    }else if(data.status == -1||data.status == "-1"){
				       alert(data.content);
				    }else if(data.status == -2||data.status == "-2"){
				       alert(data.content);
				    }else{
				       alert("网络繁忙，请稍后重试...");
				    }
				
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
	  }
</script>
</head>

<body>



<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">条件查询</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				
				

    <form class="form-search" id="queryForm" method="post" action="${ctx}/print/v2_queryPrintList" style="margin-top: 10px;">
<!-- 	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;"> -->
<!-- 		<thead> -->
<!-- 			<th style="vertical-align: middle; color: white; " colspan="1" bgcolor="#8EB4CB">条件查询</th> -->
<!-- 		</thead> -->
<!-- 		<tr><td> -->
			<div class="form-group row">
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">商家用户:</span> 
						<select class="form-control"  id="_customerCode" name="_customerCode"  value="${param._customerCode}" onchange="ajaxAreaGroup(this,'_warehouseCode');">
				        	<option value=""></option>
							<c:forEach items="${customerList}" var="customer">
								<option value="${customer.customerCode}"
								  <c:if test="${_customerCode eq customer.customerCode }">selected=selected</c:if>
								>${customer.customerName}</option>
							</c:forEach>
						</select>
					</div>
				</div>
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">作业仓库</span> 
						<select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="form-control" >
							<option value=""></option>
							<c:forEach items="${warehouseList}" var="wm">
								<option value="${wm.groupCode}"
								<c:if test="${param._warehouseCode eq wm.groupCode}">selected=selected</c:if>
								>${wm.groupName}</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">拣货类型:</span> 
						<select class="form-control"  id="_pickType" name="_pickType" >
						        <option value="" <c:if test="${param._pickType eq ''}">selected="selected"</c:if>>全选</option>
						        <option value="single" <c:if test="${param._pickType eq 'single'}">selected="selected"</c:if>>单件</option>
						        <option value="multi" <c:if test="${param._pickType eq 'multi'}">selected="selected"</c:if>>多件</option>
						</select>
					</div>
				</div>
				
				<!-- begin 添加创建者查询条件 By rongfei.zhang -->
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">创建者:</span> 
						<input type="text" id="_createName" name="_createName" value="${_createName}" class="form-control span3" >
					</div>
				</div>
				<!-- end 添加创建者查询条件 By rongfei.zhang -->
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">订单编号:</span> 
						<input type="text" id="_orderno" name="_orderno" value="${_orderno}" class="form-control span3" >
					</div>
				</div>
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">任务号:</span> 
						<input type="text" id="_taskCode" name="_taskCode" value="${_taskCode}" class="form-control span3" >
					</div>
				</div>
				
			</div>
			
<!-- 		</td></tr> -->
		
<!-- 		<tr><td> -->
		    
		    <div class="form-group row">
			    
			    <div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">快递公司: </span> 
						<select class="form-control"  id="_companyCode" name="_companyCode"  value="${param._companyCode}" onchange="changeEvent();">
						        <option value=""></option>
								<c:forEach items="${cmpList}" var="cmp">
									<option value="${cmp.companyCode}"
									  <c:if test="${param._companyCode eq cmp.companyCode }">selected=selected</c:if>
									>${cmp.companyName}</option>
								</c:forEach>
						</select> 
					</div>
				</div>
				

			    <div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">是否打印: </span> 
						<select class="form-control"  id="_printStatus" name="_printStatus" >
						        <option value="" <c:if test="${_printStatus eq ''}">selected="selected"</c:if>>全选</option>
						        <option value="printed" <c:if test="${_printStatus eq 'printed'}">selected="selected"</c:if>>已打印</option>
						        <option value="unprinted" <c:if test="${_printStatus eq 'unprinted'}">selected="selected"</c:if>>未打印</option>
						</select> 
						
					</div>
				</div>
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text"> 是否优先派送: </span> 
							<select class="form-control"   id="_psFlag" name="_psFlag" >
								<option value="-1" <c:if test="${_psFlag eq '-1'}">selected="selected"</c:if>>全部</option>
							    <option value="0"  <c:if test="${_psFlag eq '0'}">selected="selected"</c:if>>否</option>
								<option value="1"  <c:if test="${_psFlag eq '1'}">selected="selected"</c:if>>是</option>
							</select>
					</div>
				</div>
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">创建时间 :</span> 
						<div class="input-group-addon"> 
							<i class="fa fa-calendar"></i>
						</div> 
						<input type="text" name="_fromDate" id="_fromDate"  class="form-control span3"  value="${param._fromDate}"  >
						
					</div>
				</div>
				
				
				<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<span class="input-group-text">至： </span> 
						<div class="input-group-addon"> 
							<i class="fa fa-calendar"></i>
						</div> 
						<input type="text" name="_toDate" id="_toDate" class="form-control required" value="${param._toDate}" >
						
					</div>
				</div>
				
				<div class="col-sm-2" >
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text">默认加载数量： </span> 
								<select class="form-control span3" id="_num" name="_num"  >
									<option value="50"  <c:if test="${_num eq '50'}">selected="selected"</c:if>>50</option>
									<option value="100" <c:if test="${_num eq '100'}">selected="selected"</c:if>>100</option>
									<option value="150" <c:if test="${_num eq '150'}">selected="selected"</c:if>>150</option>
									<option value="200" <c:if test="${_num eq '200'}">selected="selected"</c:if>>200</option>
								</select>
					</div>
				</div>
				
			 </div>
			 <div class=" form-group row">
					<div class="col-sm-1">
					<div class="input-group col-sm-12">
						<button class="btn btn-primary" type="submit" style="margin-left: 10px;">搜索</button>		
					</div>
				</div>			
			</div>
			 
			 
<!-- 		 </td></tr> -->
<!-- 	</table> -->
	</form>
	</div></div></div></div>
	
	
	<a name='task'   role="button" data-toggle="modal" class="btn btn-primary" onclick="printPackForm(this);">打印随箱单</a>
	
	<table name='task' id="contentTable" class="table table-striped table-bordered table-condensed" style="margin-top: 5px;">
		<thead><tr>
		        <th><input type="checkbox" name="myCheckedAll" id="myCheckedAll" /></th>
		        <th>序号</th>
		        <th>商家</th>
			    <th>仓库</th>
			    <th>快递</th>
			    <th>批次</th>
			    <th>任务</th>
			    <th>是否优先派送</th>
			    <th>订单类型</th>
			    <th>运单类型</th>
			    <th>订单数量</th>
			    <th>创建者</th>
			    <th>创建时间</th>
			    <th>状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		<c:forEach items="${taskList}" var="task" varStatus="i">
			<tr id="pendPackForm_${task.id }">
			   <td align="right"> 
			   
			    <c:choose>
                   <c:when test="${task.customer.packStatus eq '0'}">
			           <input type="checkbox" name="myChecked" id="check${task.id }" value="${task.id }" disabled="disabled"/>
                   </c:when>
                   <c:otherwise>
			           <input type="checkbox" name="myChecked" id="check${task.id }" value="${task.id }" <c:if test="${task.packformStatus eq 'yes'}">disabled="disabled"</c:if>/>
                   </c:otherwise>
                </c:choose>
			  
			   </td>
			   <td align="center">${i.count}</td>
			   <td>${task.customer.customerName}</td>
			   <td>${task.warehouse.groupName}</td>
			   <td>${task.company.companyName}</td>
			   <td><a href='${ctx}/workMsg/v2_workMsgDetail/${task.batchCode}' title="批次作业记录">${task.batchCode}</a></td>
			   <td>
			     <a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode=${task.taskCode}' title="任务订单列表">${task.taskCode}</a>
			   	 <c:if test="${task.pickType eq 'single'}"><a href='${ctx}/pickTask/exportExcel_single/${task.taskCode}'><img src="${ctx}/static/v2/img/outbox.png" title="导出拣货清单"></a></c:if>
			   	 <c:if test="${task.pickType eq 'multi'}"><a href='${ctx}/pickTask/exportExcel_multi/${task.taskCode}'><img src="${ctx}/static/v2/img/outbox.png" title="导出拣货清单"></a></c:if>
			   </td>
			   <td>
				       <c:if test="${task.prioritySendFlag eq '1'}">是</c:if>
				       <c:if test="${task.prioritySendFlag eq '0'}">否</c:if>
			    </td>
			   <td>
			     <c:if test="${task.pickType eq 'single'}">单件</c:if>
			     <c:if test="${task.pickType eq 'multi'}">多件</c:if>
			   </td>
			   <td>
			     <c:if test="${task.billType eq 'cbill'}">普通运单</c:if>
			     <c:if test="${task.billType eq 'ebill'}">电子运单</c:if>
			  </td>
			  <td>
			    ${task.orderQty}
			  </td>
			  <!-- begin 添加创建者展示字段 By rongfei.zhang -->
			  <td>
			    ${task.creater.realname}
			  </td>
			  <!-- begin 添加创建者展示字段 By rongfei.zhang -->
			   <td>${fn:substring(task.createTime,5,16)}</td>
			   <td id="expressStyle${task.id}">
			     <!-- 是否打印 （printed: 已打印 未打印：unprinted） -->
			     <c:if test="${task.printStatus eq 'printed'}"><a href="${ctx}/print/v2_toReprintPage/${task.taskCode}"><font color=red>已打印</font></a></c:if>
			     <c:if test="${task.printStatus ne 'printed'}">未打印</c:if>
			   </td>
			   <td>
			   <input type="hidden" id="nowBatchCode" name="nowBatchCode">
			   <c:if test="${task.pickinfoStatus ne 'yes'}">
			 	  <a href="#printPickInfo" id="print_${task.taskCode}"  data-toggle="modal" role="button" class="btn btn-info" onclick="changeStatus('${task.taskCode}','pickInfo','${task.warehouseCode}','${task.customerCode}');" style="margin-left: 20px;">打印拣货单</a>
			   </c:if>
			   <c:if test="${task.warehouseCode eq 'DG'}">
		      		<!-- <a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary" onclick="ajaxExpressStyle('${task.companyCode }','${task.warehouseCode }','${task.customerCode}','${task.billType }');printInitExpress('${task.id}');initFirstExpress('${task.taskCode}');" style="margin-left: 20px;" id="express_${task.id }"> 打印订单条码 </a> -->
		      		<a href="#selextPrinter"  data-toggle="modal" class="btn btn-info" onclick="initPrinter('${task.batchCode}');" id="btn_printCode">打印订单条码</a>
		      	</c:if>
			      <c:if test="${task.printStatus eq 'unprinted'}">
			      	<c:if test="${task.warehouseCode ne 'DG'}">
			      		<c:if test="${task.billType eq 'cbill'}">
				        	<a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary" onclick="ajaxExpressStyle('${task.companyCode }','${task.warehouseCode }','${task.customerCode}','${task.billType }');printInitExpress('${task.id}');" style="margin-left: 20px;" id="express_${task.id }"> 打印快递单 </a>
				      	</c:if>
				      	<c:if test="${task.billType eq 'ebill'}">
				      		<a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary" onclick="ajaxExpressStyle('${task.companyCode }','${task.warehouseCode }','${task.customerCode}','${task.billType }');printInitExpress('${task.id}');initFirstExpress('${task.taskCode}');" style="margin-left: 20px;" id="express_${task.id }"> 打印电子单 </a>
				      	</c:if>
			      	</c:if>
			      </c:if>
			      <a href="${ctx}/print/v2_toReprintPage/${task.taskCode}" role="button"  class="btn btn-info">重新打印</a>
                  
			     <c:if test="${task.expressStatus eq 'yes'}">
			     	<c:if test="${task.billType eq 'cbill'}">
			        	<a href="#verifyExpress" role="button" data-toggle="modal" class="btn btn-primary"  onclick="ajaxVerifyExpress('${task.taskCode}');" style="margin-left: 20px;">验证快递单号</a>
			        </c:if>
			     </c:if>
			      
			     
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	
	<!-- 查询订单 -->
	<table name="order" class="table table-striped table-bordered table-condensed" style="margin-top: 5px;display: none;">
		<thead><tr>
		        <th>商家</th>
			    <th>仓库</th>
			    <th>批次</th>
			    <th>任务</th>
			    <th>订单</th>
			    <th>是否优先派送</th>
			    <th>订单类型</th>
			    <th>作业模式</th>
			    <th>操作</th>
			</tr></thead>
			<tr style="height: 30px;">
			   <td>${order.customerCode}</td>
			   <td>${order.warehouseCode}</td>
			   <td><a href='${ctx}/workMsg/v2_workMsgDetail/${order.batchCode}'>${order.batchCode}</a></td>
			   <td><c:if test="${task.pickType eq 'single'}"><a href='${ctx}/pickTask/exportExcel_single/${task.taskCode}'>${task.taskCode}</a></c:if>
                           <c:if test="${task.pickType eq 'multi'}"><a href='${ctx}/pickTask/exportExcel_multi/${task.taskCode}'>${task.taskCode}</a></c:if>
               </td>
			   <td>${order.order.ordeno}</td>
			   <td>
				       <c:if test="${order.prioritySendFlag eq '1'}">是</c:if>
				       <c:if test="${order.prioritySendFlag eq '0'}">否</c:if>
			    </td>
			   <td>
			     <c:if test="${order.billType eq 'cbill'}">普通运单</c:if>
			     <c:if test="${order.billType eq 'ebill'}">电子运单</c:if>
			  </td>
			  <td>
			     <c:if test="${order.flowType eq 'prePrint'}">预先打单</c:if>
			     <c:if test="${order.flowType eq 'intimePrint'}">即时打单</c:if>
			  </td>
			  <td>
			   <c:if test="${order.billType eq 'ebill'}">
			   
			    <a id="btn_print_ebill" href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn" onclick="changeStatus('${order.taskCode}','ebill','${order.warehouseCode}','${order.customerCode}');" >打印电子运单</a>
			   
			   </c:if>
			   
			  <c:if test="${order.billType eq 'cbill'}">
			   
			     <a href="#printAllPackFormStyle" role="button" data-toggle="modal" class="btn btn-primary" onclick="changeStatus('${order.taskCode}','packForm','${order.warehouseCode}','${order.customerCode}');" style="margin-left: 20px;">打印随箱单</a>
		         <a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary"  onclick="changeStatus('${order.taskCode}','express','${order.warehouseCode}','${order.customerCode}');" style="margin-left: 20px;">打印快递单</a>
			  </c:if>
			  </td>
			</tr>
	</table>
	
	
	<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="verifyExpress">
		<div class="modal-dialog">
					<div class="modal-content">
					<div class="modal-header">
						
						<h3 id="myModalLabel">
		                                                             快递单号验证
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body">
						<div class="control-group">
							<div class="controls">
								<div>
							                起始运单号: <input type="text" onBlur="verifyExpressLists(this,'first');"/>
							                 <span id="firstSpan"></span>
							               终止运单号: <input type="text" onBlur="verifyExpressLists(this,'end');" id="endExpress"/>
							                 <span id="endSpan"></span>
							              
							    </div>
							</div>
						</div>
						<div class="control-group">
							<div class="controls">
								<table  class="table table-striped table-bordered table-condensed">
								<thead><tr><th>序号</th><th>快递单号</th></tr></thead>
								<tbody id="tableVerify"></tbody>
								</table>
							</div>
						</div>
					
					</div>
		
		            <div class="modal-footer">
					    <a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					</div>
					
				</div>
			</div>
		</div>
	
	   
		<div  class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printWorkBatchExpress">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto; height: 400px">
							<div class="form-group row">
							    <div class="col-sm-9">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 选择打印机: </span> 
										<select id="expressPrint" name="packFormPrinter"  class="form-control" >
										</select>
									</div>
								</div>
							</div>
							
							<div class="form-group row">
							    <div class="col-sm-9">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 选择快递单:</span> 
										<select id="expressStylesId" name="expressStylesId"   class="form-control" onchange="getAjaxExpress();">
											<option value=""></option>
											<c:forEach items="${expressStyles}" var="obj" varStatus="in">
												<option value="${obj.id}"> ${obj.styleName} </option>
											</c:forEach>
										</select>
									</div>
								</div>
							</div>
						
						<c:if test="${order.billType ne 'ebill'}">
							<div class="form-group row">
							    <div class="col-sm-9" id = "startWaybillNODiv">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 起始运单号:</span> 
										<input type="text" id="firstExpressNumber"   class="form-control" />
									</div>
								</div>
							</div>
						</c:if>
							
							
					</div>
<!-- 					<div class="modal-footer"> -->
					  	<c:if test="${order eq null }">
			               <div class="modal-footer">
							<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrintExpress()"> 立即打印 </a>
							<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
						  </div>
			            </c:if>
						<c:if test="${order ne null }">
			               <div class="modal-footer">
							<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter('needExpressCompany')"> 立即打印</a>
							<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
						  </div>
			            </c:if>
<!-- 					</div> -->
				</div>
			</div>
		</div>
		


		<div class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="printAllPackFormStyle">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						
						<h3 id="myModalLabel">
		                                                        打印随箱单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					
					<div class="modal-body" style="height: 400px">
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择打印机: </span> 
									<select id="packFormStylePrint" name="packFormPrinter" class="form-control"  >
			
									</select>
								</div>
							</div>
						</div>
						
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择随箱单: </span> 
									<select id="packformStylesId" name="packformStyleId" class="form-control" onchange="getAjaxPackformStyle();">
										<c:forEach items="${packformStyles}" var="obj">
											<option value="${obj.id}"> ${obj.styleName} </option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
					</div>
		
		           <c:if test="${order ne null }">
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		           </c:if>
		           <c:if test="${order eq null }">
					<div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="printPackFormStyle()"> 立即打印· </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					</div>
				  </c:if>
				</div>
			</div>
		</div>
		
		
		
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printGuarantee">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印保修单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;height: 400px">
						<div class="control-group">
							<div class="controls">
								  选择打印机:
								<select id="guaranteeStylePrint" name="packFormPrinter" >
		
								</select>
							</div>
						</div>
					</div>
					
					
		
		           <c:if test="${order ne null }">
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		           </c:if>
		           <c:if test="${order eq null }">
					<div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="printAjaxGuarantee()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					</div>
				  </c:if>
		  	</div>
		  </div>
		</div>
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printPickInfo">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印拣货单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;">
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择打印机: </span> 
									<select id="pickPickPrint" name="pickPickPrint" class="form-control"  >
			
									</select>
								</div>
								
							</div>
						</div>
						
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
										<span class="input-group-text"> 纸张尺寸: </span> 
										<select id="paperSizes" name="paperSizes" class="form-control"  >
											<option value="A4" selected="selected" >A4</option>
											<option value="A5" >A5</option>
										</select>
								</div>
							</div>
						</div>
					</div>
					
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="AjaxPagePrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		  	</div>
		  </div>
		</div>
		
		<!-- 打印条码窗体1 -->
		<div  class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter">
			 <div class="modal-dialog" style="width:1000">
			<div class="modal-content">
			 <div class="modal-header">
				  <h3 id="printerNumber">打印条码</h3>
			  </div>
				
			  <div class="modal-body" style="margin-left: 100px;">
				  <select id="printerBody" name="printerBody" style="width: 300px;"></select>
			  </div>
				
			  <div class="modal-footer">
			      <a role="button" id="printer" class="btn btn-primary" onclick="clickPrinter();"  data-dismiss="modal">开始打印</a>
				  <button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true">取消</button>
			  </div>
			  </div></div>
		</div>
		
</section>
		<script type="text/javascript">
	//getAjaxPackformStyle();
	getAjaxExpress();
	var status="";
	var taskCode="";
	function changeStatus(task,item,areaGroupCode,type){
		taskCode=task;
		status=item;
		if("packForm"==item){
		    packFormPrinter("packFormStylePrint");
		 	ajaxCustomerCodePackformStyle(type);
		}else if("express"==item){
			doGetPrinters();
			ajaxGetAllExpress(type,areaGroupCode,'normal');
		}else if("ebill"==item){
			doGetPrinters();
			ajaxGetAllExpress(type,areaGroupCode,'mail');
		}else if("guarantee"==item){
			packFormPrinter("guaranteeStylePrint");
		}else if("pickInfo"==item){
			packFormPrinter("pickPickPrint");
		}
	}
	
	function pageAjaxPrinter(needExpressCompay){
		var esiValue = $("#expressStylesId").val();
		if(needExpressCompay && !esiValue){
			alert("请选择快递单");
			return;
		}
		
	    var orders='${order.order.ordeno}';
	    var taskcode='${order.taskCode}';
		   if(orders==""){
		    $("#message").html("请选择订单");
		    $("#message").show();
		    hideMessage();
		    return;
		   }
		   if("express"==status){
		    var firstExpressNumber = $("#firstExpressNumber").val();//运单号
			var expressStylesId = $("#expressStylesId").val();//快递单样式
			
			   printName=$("#expressPrint").val();
		        if(!verify(firstExpressNumber)){
		           alert("请输入正确的订单号！");
		           return;
		        }
		       ajaxPrintPackExpressOrdenos(orders,firstExpressNumber,expressStylesId);
		   }else if("packForm"==status){
			   printName= $("#packFormStylePrint").val();
		   		var packformStylesId = $("#packformStylesId").val();//随箱单样式
		   		packformName=$("#packformStylesId").text();
		        ajaxPrintPackFormOrdenos(orders,packformStylesId);
		   }else if("ebill"==status){
			   printName= $("#expressPrint").val();
			   var expressStylesId = $("#expressStylesId").val();//快递单样式
			  
			   ajaxPrintEBillExpress(orders,expressStylesId,taskcode);
		   }else if("guarantee"==status){
		   		printName = $("#guaranteeStylePrint").val(); //保修单
		   		ajaxPrintguaranteeOrdenos(orders);
		   }
		
	}
	
	function ajaxPrintPackExpressOrdenos(ordenos,firstExpress,expressId){
		 showBg();
		$.ajax({
					type : 'post',
					url : '${ctx}/print/ajaxPrintPackExpressOrdenos',
					data : 'ordenos=' + ordenos+'&firstExpress='+firstExpress+'&expressId='+expressId,
					dataType : 'json',
					success : function(data) {
						 if (data.status == "1") {
							$.each(data.content, function(i) {
								
								    var str=data.content[i].content;
								    str=str.replace(/\r\n|\n|\r/g,"");	
								    
								printExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
								
							});
						    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
						       closeBg();
						} else if (data.status == "-3") {
					    	closeBg();
							alert("请输入正确的运单号！");
						} else if (data.status == "0") {
						    closeBg();
							alert("加载错误！");
						}

					},

					error : function() {

					}
				});
		}
	
	function ajaxPrintPackFormOrdenos(ordenos,packformStyleId){
		 showBg();
		$.ajax({
					type : 'post',
					url : '${ctx}/print/ajaxPrintPackFormOrdenos',
					data : 'ordenos=' + ordenos+'&packformStyleId='+packformStyleId,
					dataType : 'json',
					success : function(data) {
						 if (data.status == "1") {
							$.each(data.content, function(i) {
								
								 printStyle(packformName,data.content[i].taskName,printName,data.content[i].content,data.content[i].ordeno,
										 data.content[i].expressNo,data.content[i].taskName,data.content[i].printerLoGo);
								
							});
						    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
						      closeBg();
						} else if (data.status == "-3") {
					    	closeBg();
							alert("请输入正确的运单号！");
						} else if (data.status == "0") {
						    closeBg();
							alert("加载错误！");
						}

					},

					error : function() {
		                alert("服务器异常1");
					}
				});
		}
		
	function ajaxPrintguaranteeOrdenos(orders){
		showBg();
		printName = $("#guaranteeStylePrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintguaranteeOrdenos',
			data : {
				ordenos:orders
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					$.each(data.workOrders,function(i,v){
							printGuarantee(v,printName);
						});
					closeBg();
					} else {
						closeBg();
					}
				 }
		});
		}
	
	function ajaxCustomerCodePackformStyle(item) {
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/packformStyle/ajaxCustomerCodePackformStyle',
					data : 'customerCode=' + item,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var _temp="";
							$.each(data.content,function(i,obj){
							       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
							    });
							
							    $("#packformStylesId").html(_temp);
							    $("#packformStylesId").trigger("chosen:updated");
						} 
					},
					error : function() {

					}
				});
	}
	
	function ajaxGetAllExpress(item,areaGroupCode,type) {
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/expressPrinting/ajaxGetAllExpress',
					data : 'customerCode=' + item+'&type='+type+'&areaGroupCode='+areaGroupCode,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var _temp="<option value=''></option>";
							$.each(data.content,function(i,obj){
							       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
							    });
							
							    $("#expressStylesId").html(_temp);
							    $("#expressStylesId").trigger("chosen:updated");
						} 
					},
					error : function() {

					}
				});
	}
</script>
</body>
</html>
